﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.ThanksGiving.command.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.common.tooltip.tooltips.equipment.*;
    import mortal.game.view.shopMall.view.*;

    public class ToolTipBaseItem extends ToolTipScaleBg implements IToolTipBaseItem
    {
        protected var _txtType:GTextFiled;
        protected var _txtName:GTextFiled;
        protected var _icon:ShopSellItem;
        protected var _txtLv:AutoLayoutTextContainer;
        protected var _txtDesc:GTextFiled;
        protected var _txtTips:GTextFiled;
        protected var _prescriptionPart:ToolTipPrescriptionPart;
        protected var _txtTodayUseTime:GTextFiled;
        protected var _line:ScaleBitmap;
        protected var _data:ItemData;

        public function ToolTipBaseItem()
        {
            this.createChildren();
            paddingBottom = 8;
            paddingLeft = 12;
            paddingRight = 8;
            paddingTop = 8;
            return;
        }// end function

        protected function resetItemDesc() : void
        {
            var _loc_2:Object = null;
            var _loc_3:TMountBlessStoneConfig = null;
            var _loc_1:* = this._data.itemInfo.alyDesc();
            if (ItemsUtil.isAdvanceBlessItem(this._data))
            {
                _loc_2 = MountUtil.getSystemObjByItem(this._data);
                _loc_3 = MountConfig.instance.getMuntBlessStoneDic(_loc_2.level);
                if (_loc_3)
                {
                    _loc_1 = _loc_1 + ("\n" + Language.getStringByParam(35630, this._data.itemInfo.htmlName, _loc_2.level, _loc_2.name, _loc_3.addBless, _loc_3.addPercent));
                }
                else
                {
                    _loc_1 = _loc_1 + ("\n" + Language.getStringByParam(35631, _loc_2.name));
                }
            }
            if (_loc_1)
            {
                if (ThanksGivingUtil2.isInActive && ItemsUtil.isGuildDonation(this._data))
                {
                    _loc_1 = Language.getString(90202) + _loc_1;
                }
                this._txtDesc.htmlText = _loc_1;
            }
            else
            {
                this._txtDesc.text = "";
            }
            this._txtDesc.height = this._txtDesc.textHeight + 7;
            return;
        }// end function

        override public function set data(param1) : void
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            this._data = param1 as ItemData;
            if (this._data == null)
            {
                return;
            }
            super.data = this._data;
            setBg(ToolTipUtil.getBgNameByColor(this._data.itemInfo.color));
            _scaleBg.setSize(250, paddingTop + paddingBottom + this._txtDesc.y + this._txtDesc.textHeight + 8);
            this._icon.itemData = this._data;
            if (this._data.itemInfo.category == EStuff._EStuffJewel || ItemsUtil.isOtherSkillBook(this._data))
            {
                this._txtLv.setText(0, Language.getStringByParam(20243, this._data.itemInfo.itemLevel));
            }
            else
            {
                this._txtLv.setText(0, Language.getStringByParam(20243, this._data.itemInfo.level));
            }
            this._txtLv.setText(1, Language.getStringByParam(20244, ColorConfig.instance.getItemColor(this._data.itemInfo.color).colorText));
            var _loc_2:* = this._data.itemInfo.beginDate.time;
            var _loc_3:* = this._data.itemInfo.endDate.time;
            if (_loc_2 == _loc_3)
            {
                this._txtLv.setText(2, Language.getString(20247));
            }
            else
            {
                _loc_5 = ClockManager.instance.nowDate.time;
                if (_loc_5 >= _loc_2 && _loc_5 < _loc_3)
                {
                    this._txtLv.setText(2, Language.getString(20245));
                }
                else
                {
                    this._txtLv.setText(2, Language.getString(20245) + Language.getString(20246));
                }
            }
            this.resetItemDesc();
            this.updateName();
            var _loc_4:* = this._txtDesc.y + this._txtDesc.height + 4;
            if (ItemsUtil.isPrescriptionItem(this._data))
            {
                _loc_4 = this.addPrescriptionPart(_loc_4);
            }
            else
            {
                this.removePrescriptionPart();
            }
            if (ItemsUtil.isLimitUseTimesItem(this._data))
            {
                _loc_6 = Cache.instance.pack.backPackCache.getTodayUsedTimes(this._data.itemInfo);
                _loc_4 = this.addLimitUseTimes(_loc_4, _loc_6, this._data.itemInfo.effect);
            }
            else
            {
                this.removeLimitUseTimes();
            }
            this._txtTips.y = _loc_4;
            this.updateBg();
            return;
        }// end function

        protected function addLimitUseTimes(param1:int, param2:int, param3:int) : int
        {
            if (this._line == null)
            {
                this._line = UIFactory.bg(-10, 0, 260, 2, this, ImagesConst.SplitLine);
            }
            this._line.y = param1;
            param1 = param1 + 6;
            if (this._txtTodayUseTime == null)
            {
                this._txtTodayUseTime = UIFactory.gTextField("", 0, 0, 220, 24, this);
                this._txtTodayUseTime.textColor = 16776960;
            }
            this._txtTodayUseTime.y = param1;
            param1 = param1 + 20;
            this._txtTodayUseTime.htmlText = Language.getStringByParam(20760, param2, param3);
            return param1;
        }// end function

        protected function removeLimitUseTimes() : void
        {
            if (this._txtTodayUseTime != null)
            {
                this._txtTodayUseTime.dispose(true);
                this._txtTodayUseTime = null;
            }
            if (this._line != null)
            {
                this._line.dispose(true);
                this._line = null;
            }
            return;
        }// end function

        protected function addPrescriptionPart(param1:int) : int
        {
            if (this._prescriptionPart == null)
            {
                this._prescriptionPart = UICompomentPool.getUICompoment(ToolTipPrescriptionPart);
            }
            this._prescriptionPart.data = this._data;
            this._prescriptionPart.y = param1;
            param1 = this._prescriptionPart.y + this._prescriptionPart.height + 6;
            this.addChild(this._prescriptionPart);
            return param1;
        }// end function

        protected function removePrescriptionPart() : void
        {
            if (this._prescriptionPart)
            {
                this._prescriptionPart.dispose();
                this._prescriptionPart = null;
            }
            this._txtTips.y = this._txtDesc.y + this._txtDesc.height;
            return;
        }// end function

        public function setBuyback(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Boolean = false;
            if (this._data.serverData.uid)
            {
                if (param1 < 0)
                {
                    this._txtTips.text = Language.getString(20248);
                    this._txtTips.textColor = 3602685;
                }
                else
                {
                    _loc_2 = GameDefConfig.instance.getEPrictUnitName(this._data.itemInfo.sellUnit);
                    _loc_3 = Cache.instance.role.enoughMoney(this._data.itemInfo.sellUnit, param1);
                    if (!_loc_3)
                    {
                        this._txtTips.textColor = 16711680;
                    }
                    else
                    {
                        this._txtTips.textColor = 65280;
                    }
                    this._txtTips.text = Language.getStringByParam(20260, param1.toString() + _loc_2);
                }
            }
            else
            {
                this._txtTips.text = "";
            }
            this.updateBg();
            return;
        }// end function

        public function updateBg() : void
        {
            _scaleBg.setSize(250, this._txtTips.y + this._txtTips.textHeight + paddingBottom + paddingTop);
            return;
        }// end function

        override public function get width() : Number
        {
            return _scaleBg.width;
        }// end function

        override public function get height() : Number
        {
            return _scaleBg.height;
        }// end function

        protected function updateName() : void
        {
            this._txtName.width = _scaleBg.width;
            var _loc_1:* = GameDefConfig.instance.getECategory(this._data.itemInfo.category);
            var _loc_2:* = Language.getString(20761);
            if (_loc_1 != null)
            {
                _loc_2 = _loc_1.text;
            }
            this._txtName.htmlText = "[" + _loc_2 + "]  " + this._data.itemInfo.htmlName;
            return;
        }// end function

        protected function createChildren() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._txtType = UIFactory.gTextField("", 16, 0, 80, 24, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", 16, 0, 288, 24, this, _loc_1);
            this._icon = UICompomentPool.getUICompoment(ShopSellItem);
            this._icon.x = 0;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._icon);
            this._icon.isShowLock = true;
            this._txtLv = new AutoLayoutTextContainer();
            this._txtLv.x = 80;
            this._txtLv.y = 35;
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.addNewText(200, "", 12, 16777215);
            this._txtLv.verticalGap = -5;
            contentContainer2D.addChild(this._txtLv);
            this._txtDesc = UIFactory.gTextField("", 0, 115, 232, 120, contentContainer2D);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            this._txtTips = UIFactory.gTextField(Language.getString(20248), 0, this._txtDesc.y + 60, 242, 20, contentContainer2D);
            this._txtTips.textColor = 3602685;
            return;
        }// end function

    }
}
